package lab01;

public class Test05 {
    public static int SumFor(int a) {
        int sum = 0;
        for (int b = 1; b < a; b++) {
            sum = sum + b;
        }
        return sum;
    }

    private static int SumDowhile(int a) {
        int i = 1;
        int sum = 0;
        do {
            sum = sum + i;
            i++;
        }
        while (i <= a);
        return sum;
    }

    private static int SumWhile(int a) {
        int i = 1;
        int sum = 0;
        while (i <= a) {
            sum = sum + i;
            i++;
        }
        return sum;
    }

    public static void main(String[] args) {
        System.out.println("For方法求和结果为：" + SumFor(10));
        System.out.println("While方法求和结果为：" + SumWhile(10));
        System.out.println("do-while方法求和结果为：" + SumDowhile(10));

    }
}